package com.ming.closeto.ui;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.ming.closeto.R;

// 由于此页面要全屏，故不继承 BaseActivity
public class ScreenBadPointActivity extends Activity implements View.OnClickListener {

    private TextView tv_screen_bg;

    // 默认下表
    private int index = 0;
    // 默认颜色
    private int [] mColor = {Color.RED, Color.GREEN, Color.BLUE, Color.BLACK, Color.WHITE, Color.GRAY};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen_bad_point);
        initView();
    }

    private void initView() {
        tv_screen_bg = (TextView) findViewById(R.id.tv_screen_bg);
        tv_screen_bg.setOnClickListener(this);
        tv_screen_bg.setBackgroundColor(mColor[index]);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_screen_bg:
                // 切换颜色
                index++;
                if (index >= mColor.length) {
                    Toast.makeText(this, "即将推出", Toast.LENGTH_SHORT).show();
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            finish();
                        }
                    }, 1500);
                } else {
                    if (mColor[index] == Color.WHITE) {
                        tv_screen_bg.setTextColor(Color.BLACK);
                    } else {
                        tv_screen_bg.setTextColor(Color.WHITE);
                    }
                    tv_screen_bg.setBackgroundColor(mColor[index]);
                }
                break;
        }
    }
}
